package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.CompanyExample.E_ADDRESS;
import static org.jsola.hr.example.CompanyExample.E_BUSINESS_SCOPE;
import static org.jsola.hr.example.CompanyExample.E_DEP_ID;
import static org.jsola.hr.example.CompanyExample.E_EMAIL;
import static org.jsola.hr.example.CompanyExample.E_INDUSTRY;
import static org.jsola.hr.example.CompanyExample.E_LEGAL_PERSON;
import static org.jsola.hr.example.CompanyExample.E_LOGO;
import static org.jsola.hr.example.CompanyExample.E_NAME;
import static org.jsola.hr.example.CompanyExample.E_OFFICIAL_WEBSITE;
import static org.jsola.hr.example.CompanyExample.E_PERSON_SIZE;
import static org.jsola.hr.example.CompanyExample.E_PROFILE;
import static org.jsola.hr.example.CompanyExample.E_TELEPHONE;
import static org.jsola.hr.example.CompanyExample.N_ADDRESS;
import static org.jsola.hr.example.CompanyExample.N_BUSINESS_SCOPE;
import static org.jsola.hr.example.CompanyExample.N_DEP_ID;
import static org.jsola.hr.example.CompanyExample.N_EMAIL;
import static org.jsola.hr.example.CompanyExample.N_INDUSTRY;
import static org.jsola.hr.example.CompanyExample.N_LEGAL_PERSON;
import static org.jsola.hr.example.CompanyExample.N_LOGO;
import static org.jsola.hr.example.CompanyExample.N_NAME;
import static org.jsola.hr.example.CompanyExample.N_OFFICIAL_WEBSITE;
import static org.jsola.hr.example.CompanyExample.N_PERSON_SIZE;
import static org.jsola.hr.example.CompanyExample.N_PROFILE;
import static org.jsola.hr.example.CompanyExample.N_TELEPHONE;

/**
 * 用工单位
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class CompanyQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 100)
    private String name;

    @ApiParam(value = N_INDUSTRY, example = E_INDUSTRY)
    @Length(max = 100)
    private String industry;

    @ApiParam(value = N_LOGO, example = E_LOGO)
    @Length(max = 100)
    private String logo;

    @ApiParam(value = N_BUSINESS_SCOPE, example = E_BUSINESS_SCOPE)
    @Length(max = 500)
    private String businessScope;

    @ApiParam(value = N_PROFILE, example = E_PROFILE)
    @Length(max = 500)
    private String profile;

    @ApiParam(value = N_LEGAL_PERSON, example = E_LEGAL_PERSON)
    @Length(max = 20)
    private String legalPerson;

    @ApiParam(value = N_ADDRESS, example = E_ADDRESS)
    @Length(max = 100)
    private String address;

    @ApiParam(value = N_PERSON_SIZE, example = E_PERSON_SIZE)
    @Length(max = 50)
    private String personSize;

    @ApiParam(value = N_OFFICIAL_WEBSITE, example = E_OFFICIAL_WEBSITE)
    @Length(max = 100)
    private String officialWebsite;

    @ApiParam(value = N_TELEPHONE, example = E_TELEPHONE)
    @Length(max = 50)
    private String telephone;

    @ApiParam(value = N_EMAIL, example = E_EMAIL)
    @Length(max = 50)
    private String email;

    @ApiParam(value = N_DEP_ID, example = E_DEP_ID)
    @Length(max = 32)
    private String depId;

    @ApiParam(value = "查询类型，1查询所有用工单位")
    private Integer queryType ;

    @ApiParam(value = "是否包含当前公司,默认 是")
    private Boolean showCurrentCompany = true;

    @ApiParam(value = "当前公司id,不包含当前公司的时候使用")
    private String currentCompanyId;

    @ApiParam(value = "批量操作id列表")
    private List<String> ids;

    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public CompanyQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

